﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;

namespace GK320_Helper
{
    /// <summary>
    /// UserInterface.xaml 的交互逻辑
    /// </summary>
    public partial class UserInterface : MetroWindow
    {
        bool isLoaded = false;
        double Ani, Window, GD;
        double changetoWin = 1;
        double changetoAni = 1;
        double changetoGd = 1;
        public UserInterface()
        {
            InitializeComponent();
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.StandardInput.WriteLine("adb shell wm density" + "&exit");
            p.StandardInput.AutoFlush = true;
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();
            NowDensity.Content = output;
            isLoaded = true;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

        private void ChangeDPI_Click(object sender, RoutedEventArgs e)
        {

        }

        private void ChangeWindow_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.StandardInput.WriteLine("adb shell settings put global window_animation_scale " + changetoAni.ToString() + "&exit");
            p.StandardInput.AutoFlush = true;
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();
        }

        private void ChangeGD_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.StandardInput.WriteLine("adb shell settings put global transition_animation_scale " + changetoGd.ToString() + " & exit");
            p.StandardInput.AutoFlush = true;
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();
        }

        private void ChangeAnimator_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.StandardInput.WriteLine("adb shell settings put global animator_duration_scale " + changetoWin.ToString() + "&exit");
            p.StandardInput.AutoFlush = true;
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();
        }

        private async void Tip0_Click(object sender, RoutedEventArgs e)
        {
            await this.ShowMessageAsync("动画缩放修改建议", "1.窗口动画缩放是对一个窗口进行缩放动画，Activity之间跳转时，不让应用显得生硬，有时加入切换时的动画效果，看需求来添加动画效果。"+"\n"+ "2.过渡动画缩放作用，用于显示特效和动画效果，例如窗口打开关闭时的缩放效果，窗口切换的淡入淡出效果等。"+"\n"+ "3.动画程序时长调整一般就是指动画的播放时间，用户可以根据自己的需求来调整动画播放的时间。"+"\n"+ "4.窗口动画缩放在提升手机性能的同时必然会影响手机视觉画面效果，但是不会影响手机的正常功能。"+"\n"+ "5.窗口动画缩放在安卓手机关闭窗口动画缩放之后，可以提升手机的使用流畅程度，手机本身硬件配置不高的情况下，可以提升手机的使用性能。");

        }

        private void Tip2_Click(object sender, RoutedEventArgs e)
        {

        }

        private async void Tip_Click(object sender, RoutedEventArgs e)
        {
            await this.ShowMessageAsync("DPI修改建议", "分辨率又称解析度、解像度，是用来决定了位图图像细节的精细程度。而dpi（Dots Per Inch）是其量度单位，表示每1英寸上的点数。默认dpi为120，若使用一些软件如QQ需要将DPI改为70~80才可正常展示页面内容");
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (isLoaded == true)
            {
                string Aniani = ComboWindow.SelectedItem.ToString();
                
                if (Aniani.IndexOf("2x") != -1) changetoWin = 2;
                else if (Aniani.IndexOf("0.25") != -1) changetoWin = 0.25;
                else if (Aniani.IndexOf("0.75") != -1) changetoWin = 0.75;
                else if (Aniani.IndexOf("1x") != -1) changetoWin = 1;
                else if (Aniani.IndexOf("1.5x") != -1) changetoWin = 1.5;
                else if (Aniani.IndexOf("0") != -1) changetoWin = 0;
                

            }
        }

        private void ComboWindow_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (isLoaded == true)
            {
                string windowani = ComboWindow.SelectedItem.ToString();
                
                if (windowani.IndexOf("2x") != -1) changetoAni = 2;
                else if (windowani.IndexOf("0.25") != -1) changetoAni = 0.25;
                else if (windowani.IndexOf("0.75") != -1) changetoAni = 0.75;
                else if (windowani.IndexOf("1x") != -1) changetoAni = 1;
                else if (windowani.IndexOf("1.5x") != -1) changetoAni = 1.5;
                else if (windowani.IndexOf("0") != -1) changetoAni = 0;
                
                
            }

            
            
        }

        private void ComboGD_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (isLoaded == true)
            {
                string GDa = ComboWindow.SelectedItem.ToString();
                

                if (GDa.IndexOf("2x") != -1) changetoGd = 2;
                else if (GDa.IndexOf("0.25") != -1) changetoGd = 0.25;
                else if (GDa.IndexOf("0.75") != -1) changetoGd = 0.75;
                else if (GDa.IndexOf("1x") != -1) changetoGd = 1;
                else if (GDa.IndexOf("1.5x") != -1) changetoGd = 1.5;
                else if (GDa.IndexOf("0") != -1) changetoGd = 0;
                

            }
        }
    }
}
